/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CompanyExtManager;
/*     */ import com.newcrm.db.UserVOIPManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.PhoneBoxUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class VOIPDialoutAreaReport extends AbstractVOIPReport
/*     */ {
/*  32 */   private static Logger logger = Logger.getLogger(VOIPDialoutAreaReport.class
/*  33 */     .getName());
/*     */ 
/*     */   public VOIPDialoutAreaReport(AbstractHttpServlet servlet)
/*     */   {
/*  36 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  43 */     User user = super.getLoginUser(request);
/*     */ 
/*  45 */     if ((!user.isAdmin()) && (!user.isGroupAdmin())) {
/*  46 */       logger.warn("user not admin and group admin , userId: " + 
/*  47 */         user.userId);
/*  48 */       showErrorMessage(response, "只有管理员和部门管理员才有权限查看通话统计");
/*  49 */       return;
/*     */     }
/*     */ 
/*  52 */     CompanyExtManager companyExtManager = new CompanyExtManager();
/*  53 */     String companyId2 = companyExtManager.getFieldValue(user.companyId, 
/*  54 */       4);
/*  55 */     String password = companyExtManager.getFieldValue(user.companyId, 
/*  56 */       5);
/*  57 */     if ((companyId2 == null) || (companyId2.trim().length() == 0) || 
/*  58 */       (password == null) || (password.trim().length() == 0)) {
/*  59 */       logger.warn("not set companyId or passwrod");
/*  60 */       showErrorMessage(response, "系统设置中，没有设置呼叫中心账号和密码信息");
/*  61 */       return;
/*     */     }
/*     */ 
/*  64 */     response.setContentType("text/html;charset=utf-8");
/*  65 */     PrintWriter out = response.getWriter();
/*     */ 
/*  68 */     String searchDate = Util.getURLParameter(request
/*  69 */       .getParameter("searchDate"));
/*  70 */     int minTotalTime = Util.getURLIntParameter(request
/*  71 */       .getParameter("minTotalTime"));
/*  72 */     int maxTotalTime = Util.getURLIntParameter(request
/*  73 */       .getParameter("maxTotalTime"));
/*     */ 
/*  75 */     String seatNum = Util.getURLParameter(request.getParameter("seatNum"));
/*     */ 
/*  77 */     if ((!user.isAdmin) && (user.isGroupAdmin))
/*     */     {
/*  81 */       UserVOIPManager manager = new UserVOIPManager();
/*  82 */       List items = manager
/*  83 */         .getUsersVOIPInfos(user.companyId);
/*     */ 
/*  85 */       if ((items == null) || (items.size() == 0)) {
/*  86 */         logger.warn("该公司中，没有设置呼叫中心坐席账号, companyId " + user.companyId);
/*  87 */         showErrorMessage(response, "该员工没有设置呼叫中心账号");
/*  88 */         return;
/*     */       }
/*     */ 
/*  91 */       CompanyInfo company = super.getCompany(request);
/*  92 */       if (company == null) {
/*  93 */         logger.warn("company is null ");
/*  94 */         showErrorMessage(response, "通话记录获得失败");
/*  95 */         return;
/*     */       }
/*     */ 
/*  99 */       for (Object itemO : items) {
                    Map item = (Map) itemO;
/* 100 */         int groupId = ((Integer)item.get("GroupId")).intValue();
/* 101 */         if (company.isGroupAdmin(user, groupId))
/*     */         {
/* 104 */           if ((seatNum == null) || (seatNum.length() == 0))
/* 105 */             seatNum = (String)item.get("UserName");
/*     */           else {
/* 107 */             seatNum = seatNum + "," + (String)item.get("UserName");
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 112 */     String startDate = "";
/* 113 */     String endDate = "";
/* 114 */     if ((searchDate != null) && (searchDate.trim().length() > 0)) {
/* 115 */       int idx = searchDate.indexOf("~");
/* 116 */       if (idx > 0) {
/* 117 */         startDate = searchDate.substring(0, idx).trim();
/* 118 */         endDate = searchDate.substring(idx + 1).trim();
/* 119 */       } else if (idx == 0) {
/* 120 */         endDate = searchDate.substring(idx + 1).trim();
/*     */       } else {
/* 122 */         startDate = searchDate;
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 127 */     String body = PhoneBoxUtil.getAreaReport(companyId2, password, 
/* 128 */       minTotalTime, maxTotalTime, seatNum, startDate, endDate);
/* 129 */     if ((body == null) || (body.trim().length() == 0)) {
/* 130 */       super.showErrorMessage(response, "获得统计信息失败，请稍后再试");
/* 131 */       return;
/*     */     }
/* 133 */     out.println(body);
/* 134 */     out.flush();
/* 135 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.VOIPDialoutAreaReport
 * JD-Core Version:    0.6.1
 */